#ifndef  APPLET
#define  APPLET

#include <QtGui/QCheckBox>
#include <QtGui/QPushButton>
#include <QtGui/QVBoxLayout>
#include <QtGui/QLabel>
#include <QtGui/QTextEdit>
#include <QtGui/QSlider>

#include "runPython.hpp"

struct  ManualSettings
{
	const float step;

	int baseSpeedMod;
	int arm1SpeedMod;
	int arm2SpeedMod;
	int jawsSpeedMod;

	float base;
	float arm1;
	float arm2;
	float jaws;

	ManualSettings();

	static void set(const float _distance, float & _limb );
};

void usbCommunicaton( unsigned _command, float _move );

class Applet : public QWidget
{
	Q_OBJECT
public:
	Applet();

private:
	void executeSingleCommand( QString const & _command );

private slots:
	void executeCommands();
	void wait( unsigned waitTime );

	void run();
	void stop();
	void baseSpeedModify(int _mod);
	void arm1SpeedModify(int _mod);
	void arm2SpeedModify(int _mod);
	void jawsSpeedModify(int _mod);

	void connect();
	void openScript();
	void saveScript();
private:
	bool event(QEvent *event);
private:
	QPushButton * save;
	QPushButton * load;
	QPushButton * button;
	QPushButton * stopButton;
	QTextEdit * edit;
	QTimer *timer;
	QCheckBox * m_checkBox;

	QSlider * m_baseSlider;
	QSlider * m_baseArm1Slider;
	QSlider * m_baseArm2Slider;
	QSlider * m_baseJawsSlider;

	QPushButton * connectButton;
	QLabel * m_connectionStatus;
	Python * m_python;
};

class Timer : public QObject
{
	Q_OBJECT
public:
	void wait( unsigned waitTime );
private slots:

	void takeOffLock();
private:
	volatile bool  lock;
};

bool
stop();

void
wait( unsigned waitTime );

void
baseSpeedModify(float _mod);

void
arm1SpeedModify(float _mod);

void
arm2SpeedModify(float _mod);

void
jawsSpeedModify(float _mod);

class TexteEdit : public QTextEdit
{
	Q_OBJECT

public:
	TexteEdit( QWidget *  _parent );

public slots:
	void passEvents(bool _pass);
protected:
	bool event(QEvent *event);
private:
	bool m_passEvent;
};

#endif
